# vim: ts=4:sw=4:syntax=perl

# Take all the args and update portal ... and then
# redirect to page in the LP parameter.
use gri_secmgr qw(get_user_name redirect_header);
use gri_user_alert_config;
use File::Basename;
use xml_helper;
use Data::Dumper;
use gri2_requests;

sub mm_cancel_request_process($) {
my $id=shift;
my $_aa=new xml_helper();

	# We can deny access via this mechanism in either of the
	# following cases (access which should have been checked before getting here..).
	# 1. We are one of the owners of the portal
	# 2. Have general portal_admin access

	my $user_name=get_user_name();
	if(!defined($user_name) || $user_name eq "public") {
		html_error("Please login to perform this action.");
	}
	my $req_dir=$::GRI_FRONTEND->get_directory("requests");
	if(!defined($req_dir)) {
		return html_error("Failed to find 'requests' directory.");
	}
	my $rdb=new gri2_requests("$req_dir/requests.db");
	if(!defined($rdb)) {
		my ($rc,$str)=gri2_requests::error();
		return html_error("Failed to open requests database: $str");
	}
	my $err=$rdb->user_cancel_request({user => $user_name, id => $id});

	if(defined($err->{error})) {
		return html_error($err->{error});
	}
	my $link="$url_prefix$::ENV{SCRIPT_NAME}/users_requests_summary_page";
	redirect_header(path => $link);
	exit;
}

1;
